package com.chenqq.camerademo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.view.View;

import com.chenqq.camerademo.camera.handler.AbstractUVCCameraHandler;
import com.chenqq.camerademo.camera.helper.UsbHelperTools;
import com.chenqq.camerademo.camera.receiver.USBReceiver;
import com.chenqq.camerademo.camera.widget.CameraView;

public class MainActivity extends AppCompatActivity {

    private CameraView cameraView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        registerBroadcastResceir();
    }

    private void initView() {
        cameraView = findViewById(R.id.camera_view);

    }

    private void registerBroadcastResceir() {
        UsbHelperTools.getInStance().registerUsbReceiver(this,0);
    }

    @Override
    protected void onStart() {
        super.onStart();
        UsbHelperTools.getInStance().checkStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
//        cameraView.setDefaultPreviewSize(1920,1080);
    }

    @Override
    protected void onDestroy() {
        unResister();
        if (cameraView!=null){
            cameraView.closeCamera();
        }

        super.onDestroy();
    }

    private void unResister() {
        UsbHelperTools.getInStance().unRegisterUsbReceiver(this);
    }

    public void startVideo(View view) {
         if (cameraView!=null){
             cameraView.startRecord("",null);
         }

    }

    public void startPicture(View view) {
        if (cameraView!=null){
            cameraView.capturePicture("",null);
        }

    }

    public void stopVideo(View view) {
        if (cameraView!=null){
            cameraView.stopPusher();
        }
      
//        cameraView.setDefaultPreviewSize(1920,1080);
    }
}